package com.qf.cardlike.controller;

import com.qf.cardlike.domain.User;
import com.qf.cardlike.response.Response;
import com.qf.cardlike.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @author zed
 * @date 2022/5/16 21:10
 */
@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    /**
     * 登录
     * @param user 用户对象：名字/密码
     * @return 返回对象
     */
    @PostMapping("login")
    public Response<User> login(@RequestBody User user) {
        User login = userService.login(user.getUsername(), user.getPassword());
        if (Objects.nonNull(login)) {
            return Response.success(login);
        } else {
            return Response.fail();
        }
    }

    /**
     * 喜欢或者不喜欢[删除]名片
     * @param uid 用户ID
     * @param cid 名片ID
     * @param like true:喜欢  false:不喜欢/删除
     * @return 对象
     */
    @GetMapping("like")
    public Response<User> like(Integer uid, Integer cid,Boolean like) {
        User user = userService.likeCard(uid, cid, like);
        return Response.success(user);
    }

}
